$(document).ready(function() {

	var urlBase = $('#base_url').val();

	// Grid
	var oImportacao = $('#tbArquivosImportados').dataTable({
	    "bServerSide": true,
	    "bProcessing": false,
	    "sAjaxSource": "importacao/ajaxBuscarArquivosImportados",
		"sServerMethod": "POST",
		"iDisplayLength": 25,
		"bAutoWidth": false,
	    "fnServerParams": function ( aoData ) {
	      	aoData.push( 
	      		{ "name": "dataArquivosDe", "value": $('#dataArquivosDe').val() },
	      		{ "name": "dataArquivosAte", "value": $('#dataArquivosAte').val() },
	      		{ "name": "nomeArquivo", "value": $('#nomeArquivo').val() },
	      		{ "name": "tipoParcela", "value": $('#tipoParcela').val() },
	      		{ "name": "statusDropdown", "value": $('#statusDropdown').val() }
      		);
	    },
		"sPaginationType": "full_numbers",
		"bStateSave": false,
		"sDom": '<"top">lrt<"bottom"ip><"clear">',
		// "bFilter": true,
		"oLanguage": {
			"sUrl": urlBase + 'application/assets/datatables_language.txt', // arquivo que contém a tradução dos parametros datatables
		},
		"aaSorting": [[ 1, "desc" ]], // Default order
	    "aoColumns": [
	    	{"sTitle": "<input type='checkbox' id='checkMarcaRegistros' class='alinhaTh'>", "sWidth": "3%", "sName": "marcarArquivos", "bSortable": false, "sClass":"center"},
			{"sTitle": "Data", "sWidth": "10%", "aTargets": ['data'], "sName":"aiDataUpload", "asSorting":["desc", "asc"]},
			{"sTitle": "Nome do Arquivo", "sWidth": "50%", "aTargets": [1], "sName":"aiNomeArquivo", "bSortable": true, "asSorting":["asc", "desc"]},
			{"sTitle": "Tipo Parcelas", "sWidth": "10%", "aTargets": [2], "sName":"aiTipoParcela"},
			{"sTitle": "Usuário", "sWidth": "15%", "aTargets": [3], "sName":"avStatus"},
			{"sTitle": "Status", "sWidth": "3%", "aTargets": [4], "sName":"avMarcarNaoLido", "sClass":"center", "bSortable":false},
			{"sTitle": "Opções", "sWidth": "9%", "aTargets": [5], "sName":"avOpcoes", "sClass":"center", "bSortable":false},
      	],
	});

	// Acao do formulário de buscas
	$('#fBuscaArquivos').submit(function() {
		oImportacao.fnDraw();
	})

	// Limpa os filtros
	$('#limparBuscaArquivos').click(function() {
		$('#fBuscaArquivos')[0].reset();
		oImportacao.fnDraw();
	})


	if ($('#validateUpload').length > 0) {

		setTimeout(function() {
			$('#validateUpload').fadeOut(500);
		}, 5000)
	}

});